# -*- coding: utf-8 -*-
# @Time      : 2024/5/15 10:02
# @Author    : 未命名
# @File      : testcloud.py
# @Software  : PyCharm

import jieba    #分词
from matplotlib import pyplot as plt
from wordcloud import WordCloud
from PIL import Image
import numpy as np
import sqlite3


con = sqlite3.connect('movie.db')
cur = con.cursor()
sql = "select instroduction from movie250"
data = cur.execute(sql)
text = ""
for item in data:
    text = text + item[0]
# print(text)
cur.close()
con.close()

#应用特定的图片合成词云
cut = jieba.cut(text, cut_all=False)
string = ' '.join(cut)
print(string)

img = Image.open(r'.\static\assets\img\tree.jpg')
img_array = np.array(img)

wc = WordCloud(
    background_color='white',
    mask=img_array,
    font_path='msyh.ttc'    #在计算机C盘中FONTS查找字体
)

wc.generate_from_text(string)
plt.figure(1)
plt.imshow(wc)
plt.axis('off')
#plt.show()

plt.savefig(r'.\static\assets\img\word.jpg', dpi=500)





